const fs = require("fs")
const esprima = require("esprima")
const estraverse = require("estraverse")
const escodegen = require("escodegen")
const iconv = require("iconv-lite")
const de = require("./en")


var content = fs.readFileSync("./de.js",{encoding:"binary"});
var buf = new Buffer.from(content, "binary");
var code = iconv.decode(buf, "utf-8");


// 将js混淆代码转为ast 语法树
var ast = esprima.parse(code);
// console.log(ast);
ast = estraverse.replace(ast,{
    enter: function (node){
        if(node.type=="CallExpression" && node.callee.type=="Identifier" && node.callee.name=="_0x28d4" && node.arguments.length==2 &&
        node.arguments[0].type=="Literal" && node.arguments[1].type=="Literal"){
            var val = de._0x28d4(node.arguments[0].value, node.arguments[1].value);
            return {
                type:esprima.Syntax.Literal,
                value:val,
                raw:val
            }

        }
    }
})

//将ast 语法树生成js代码
var code = escodegen.generate(ast);
console.log(code);
